package com.itheima.api.config;

import com.itheima.api.client.fallback.ItemClientFallbackFactory;
import com.itheima.common.context.BaseContext;
import feign.RequestInterceptor;
import feign.RequestTemplate;
import org.springframework.context.annotation.Bean;

public class DefaultFeignConfig {
    @Bean
    public RequestInterceptor userInfoInterceptors() {
        return new RequestInterceptor() {
            @Override
            public void apply(RequestTemplate requestTemplate) {
                Long currentId = BaseContext.getCurrentId();
                if (currentId != null){
                    requestTemplate.header("user-info",currentId.toString());
                }
            }
        };
    }
    @Bean
    public ItemClientFallbackFactory itemClientFallbackFactory() {
        return new ItemClientFallbackFactory();
    }
}
